//
//  TopTableViewCell.m
//  MountEverestFM
//
//  Created by ChenNing on 15/10/31.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "TopTableViewCell.h"

@interface TopTableViewCell()
// too图
@property(nonatomic,strong)UIImageView *topImageView;
// 小标题
@property(nonatomic,strong)UILabel *titleLabel;
// 子标题1
@property(nonatomic,strong)UILabel *chliditleLabel1;
// 子标题1
@property(nonatomic,strong)UILabel *chliditleLabel2;
// 箭头
@property(nonatomic,strong)UIImageView *rightImageView;
// cell分割线
@property(nonatomic,strong)UIImageView *lineImageView;
@end

@implementation TopTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.topImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_topImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        
        self.chliditleLabel1 = [[UILabel alloc] init];
        self.chliditleLabel1.font = [UIFont systemFontOfSize:14];
        self.chliditleLabel1.textColor = [UIColor grayColor];
        [self.contentView addSubview:_chliditleLabel1];
        
        self.chliditleLabel2 = [[UILabel alloc] init];
        self.chliditleLabel2.font = [UIFont systemFontOfSize:14];
        self.chliditleLabel2.textColor = [UIColor grayColor];
        [self.contentView addSubview:_chliditleLabel2];
        
        self.rightImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_rightImageView];
        
        self.lineImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_lineImageView];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.topImageView.frame = CGRectMake(FM_Screen_Pts_Width*10, FM_Screen_Pts_Height*10, FM_Screen_Pts_Width*80, FM_Screen_Pts_Width*80);
    self.titleLabel.frame = CGRectMake(FM_Screen_Pts_Width*100, FM_Screen_Pts_Height*10, FM_Screen_Width-FM_Screen_Pts_Width*100, FM_Screen_Pts_Width*30);
    
    self.chliditleLabel1.frame = CGRectMake(FM_Screen_Pts_Width*100, FM_Screen_Pts_Height*10+FM_Screen_Pts_Width*30, FM_Screen_Width-FM_Screen_Pts_Width*100, FM_Screen_Pts_Width*25);
    
    self.chliditleLabel2.frame = CGRectMake(FM_Screen_Pts_Width*100, FM_Screen_Pts_Height*10+FM_Screen_Pts_Width*55, FM_Screen_Width-FM_Screen_Pts_Width*100, FM_Screen_Pts_Width*25);
    
    self.lineImageView.frame = CGRectMake(FM_Screen_Pts_Width*100, FM_Screen_Pts_Width*80+FM_Screen_Pts_Height*19, FM_Screen_Width-FM_Screen_Pts_Width*100, FM_Screen_Pts_Height*1);
}

// 重写set方法
- (void)setTopDictionary:(NSDictionary *)topDictionary
{
    if (_topDictionary != topDictionary) {
        _topDictionary = topDictionary;
    }
    [self setTopInfo:topDictionary];
}

// 设置值
- (void)setTopInfo:(NSDictionary *)topDictionary
{
    NSURL *topImageUrl = [NSURL URLWithString:[self.topDictionary objectForKey:@"coverPath"]];
    [self.topImageView sd_setImageWithURL:topImageUrl placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
    
    NSString *titleStr = [self.topDictionary objectForKey:@"title"];
    self.titleLabel.text = titleStr;
    
    NSArray *childArr = [self.topDictionary objectForKey:@"firstKResults"];
    for (NSInteger i=0; i<childArr.count; i++) {
        if (i==0) {
            self.chliditleLabel1.text = [NSString stringWithFormat:@"%d  %@",i+1,[[childArr objectAtIndex:i] objectForKey:@"title"]];
        }
        if (i==1) {
            self.chliditleLabel2.text = [NSString stringWithFormat:@"%d  %@",i+1,[[childArr objectAtIndex:i] objectForKey:@"title"]];
        }
    }
    self.lineImageView.image = [UIImage imageNamed:@"line_horizeontal@2x.png"];
}

@end
